<template>
  <div class="edit_container sas-scale-edit">
    <div class="btn_box">
      <el-button @click.stop="goBack">返回</el-button>
    </div>
    <SasScale ref="SasScale" :user="user" :data="form" />
    <div class="submit_btn_box">
      <el-button type="primary" :loading="loading" @click.stop="submit">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getAnxiety, setAnxiety } from '@/api/anxiety';
import SasScale from '@/views/assessSys/components/psychology/sasScale.vue';
export default {
  name: '',
  components: { SasScale },
  data() {
    return {
      user: {},
      form: {},
      loading: false
    }
  },
  created() {
    this.getData();
  },
  methods: {
    /**
     * 获取数据，进行回显
     */
    getData() {
      let { type = 0, source: evaluateSource = 3, id: relationId = null } = this.$route.query;
      let form = { type, evaluateSource, relationId };
      getAnxiety(form).then(({ content = {} }) => {
        let { patientName, department, bedNum, admissionNum, gender, ...rest } = content;
        this.user = { patientName, department, bedNum, admissionNum, gender };
        this.form = rest;
      });
    },
    goBack() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.back()
    },
    submit() {
      let { source: evaluateSource = 3, id: relationId = null } = this.$route.query;
      let form = { evaluateSource, relationId, ...this.$refs.SasScale.getForm() };
      this.loading = true;
      setAnxiety(form).then(({ code = 500 }) => {
        this.loading = false;
        if (!code) {
          this.$message.success('成功');
          this.goBack();
        };
      });
    }
  },
}
</script>
<style lang="scss" scoped>
@import url("../style.scss");
.submit_btn_box {
  .el-button {
    margin: 0 auto;
  }
}
</style>
